package com.erp.service.util.net;

import java.io.IOException;
import java.io.InputStream;
import java.util.zip.GZIPInputStream;
import org.apache.http.entity.HttpEntityWrapper;
import org.apache.http.HttpEntity;
/**
 * GZIP解压
 * @author ccl
 *
 */
class GzipDecompressingEntity extends HttpEntityWrapper {

	/**
	 * 构造函数
	 * 
	 */
    public GzipDecompressingEntity(final HttpEntity entity) {
        super(entity);
    }

    /**
     * 获取输入流
     */
    public InputStream getContent()
        throws IOException, IllegalStateException {

        // the wrapped entity's getContent() decides about repeatability
        InputStream wrappedin = wrappedEntity.getContent();

        return new GZIPInputStream(wrappedin);
    }

    /**
     * 获取内容长度，因为压缩的这个未知，所以返回-1
     */
    public long getContentLength() {
        // length of ungzipped content is not known
        return -1;
    }

}
